home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / POVSRC / SOURCE / TemplateMenu.c < prev    next >
Text File  |  1994-02-09  |  6KB  |  192 lines

  1. /*
  2. ==============================================================================
  3. Project:    POV-Ray
  4.  
  5. Version:    2.2
  6.  
  7. File Name:    TemplateMenu.c
  8.  
  9. Description:
  10.     Template text insertion menus for POV-Ray.
  11.  
  12.     This is the main source file, containing the private definitions and
  13.     code to implement all the needed external and internal support functions.
  14.  
  15. Related Files:
  16.     TemplateMenu.h    - Header for these routines
  17. ------------------------------------------------------------------------------
  18. Author:
  19.     Eduard [esp] Schwan
  20. ------------------------------------------------------------------------------
  21.     from Persistence of Vision Raytracer
  22.     Copyright 1993 Persistence of Vision Team
  23. ------------------------------------------------------------------------------
  24.     NOTICE: This source code file is provided so that users may experiment
  25.     with enhancements to POV-Ray and to port the software to platforms other 
  26.     than those supported by the POV-Ray Team.  There are strict rules under
  27.     which you are permitted to use this file.  The rules are in the file
  28.     named POVLEGAL.DOC which should be distributed with this file. If 
  29.     POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  30.     Team Coordinator by leaving a message in CompuServe's Graphics Developer's
  31.     Forum.  The latest version of POV-Ray may be found there as well.
  32.  
  33.     This program is based on the popular DKB raytracer version 2.12.
  34.     DKBTrace was originally written by David K. Buck.
  35.     DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  36. ------------------------------------------------------------------------------
  37. More Info:
  38.     This Macintosh version of POV-Ray was created and compiled by Jim Nitchals
  39.     (Think 5.0) and Eduard Schwan (MPW 3.2), based (loosely) on the original
  40.     port by Thomas Okken and David Lichtman, with some help from Glenn Sugden.
  41.  
  42.     For bug reports regarding the Macintosh version, you should contact:
  43.     Eduard [esp] Schwan
  44.         CompuServe: 71513,2161
  45.         Internet: jl.tech@applelink.apple.com
  46.         AppleLink: jl.tech
  47.     Jim Nitchals
  48.         Compuserve: 73117,3020
  49.         America Online: JIMN8
  50.         Internet: jimn8@aol.com -or- jimn8@applelink.apple.com
  51.         AppleLink: JIMN8
  52. ------------------------------------------------------------------------------
  53. Change History:
  54.     920901    [esp]    Created
  55.     920906    [esp]    Added auto-scroll to new insertion point
  56.     921226    [esp]    More error checking (& returning) in InitTemplateMenu
  57.     931001    [esp]    version 2.0 finished (Released on 10/4/93)
  58.     931001    [esp]    Added code to delete current selection upon insert of new template
  59. ==============================================================================
  60. */
  61.  
  62. /*==== POV-Ray std headers ====*/
  63. #include "povmac.h"
  64.  
  65.  
  66. /*==== Macintosh-specific headers ====*/
  67. // NOTE: _H_MacHeaders_ is defined by Think C if it is using
  68. // precompiled headers.  This is only for compilation speed improvement.
  69. #if !defined(_H_MacHeaders_)
  70. #include <errors.h>
  71. #include <resources.h>
  72. #include <memory.h>
  73. #include <menus.h>
  74. #endif // _H_MacHeaders_
  75.  
  76.  
  77. /*==== POV-Ray text editor header ====*/
  78. #include "TextEditor.h"
  79.  
  80.  
  81. #include "TemplateMenu.h"
  82.  
  83.  
  84. /*==== definitions ====*/
  85.  
  86. #define    TEXT_RSRC_ID        200        // 200.., 300.., 400..
  87.  
  88. MenuHandle    gMacroMenus[NUM_MACRO_MENUS];
  89.  
  90.  
  91. // ==============================================
  92. OSErr InitTemplateMenu(void)
  93. {
  94.     Boolean        endOfList;
  95.     short        anError = noErr;
  96.     short        theMenuID;
  97.     short        theItemID;
  98.     Handle        theRsrcHandle;
  99.     short        theRsrcID;
  100.     ResType        theRsrcType;
  101.     Str255        theRsrcName;
  102.  
  103.     // get submenus
  104.     for (theMenuID=0; theMenuID<NUM_MACRO_MENUS; theMenuID++)
  105.     {
  106.         gMacroMenus[theMenuID] = GetMenu(macmn_sub_ID+theMenuID);
  107.         anError = ResError();
  108.         if (gMacroMenus[theMenuID] == NULL)
  109.             anError = resNotFound;
  110.  
  111.         if (!anError)
  112.         {
  113.             // add TEXT items to this menu
  114.             theItemID = TEXT_RSRC_ID + (100*theMenuID);
  115.             endOfList = false;
  116.             do {
  117.                 theRsrcHandle = GetResource('TEXT', theItemID);
  118.                 anError = ResError();
  119.                 if (theRsrcHandle == NULL)
  120.                     anError = resNotFound;
  121.  
  122.                 // if we just hit end of list of resources, not really an error...
  123.                 if (anError == resNotFound)
  124.                 {
  125.                     anError = noErr;
  126.                     endOfList = true;
  127.                 }
  128.  
  129.                 // Get its name
  130.                 if (!endOfList && !anError)
  131.                 {
  132.                     GetResInfo(theRsrcHandle, &theRsrcID, &theRsrcType, theRsrcName);
  133.                     anError = ResError();
  134.                 }
  135.  
  136.                 // add it to the menu
  137.                 if (!endOfList && !anError)
  138.                 {
  139.                     AppendMenu(gMacroMenus[theMenuID], theRsrcName);
  140.                     ReleaseResource(theRsrcHandle);
  141.                     theItemID++;
  142.                 }
  143.             } while (!endOfList && !anError);
  144.     
  145.             // insert submenu under rug
  146.             if (!anError)
  147.                 InsertMenu(gMacroMenus[theMenuID], -1);
  148.  
  149.         }
  150.     }
  151.     return anError;
  152. } // InitTemplateMenu
  153.  
  154.  
  155. // ==============================================
  156. void HandleTemplateMenu(short theMenuID, short theItem)
  157. {
  158.     short        anError = noErr;
  159.     short        theOffset;
  160.     short        theRsrcID;
  161.     Handle        theRsrcHandle;
  162.  
  163.     theOffset = macmn_sub_ID;
  164.     theOffset = theMenuID-macmn_sub_ID;
  165.     if ((theOffset < NUM_MACRO_MENUS) && (gMacroMenus[theOffset] != NULL))
  166.     {
  167.         // get the text from the resource list
  168.         theRsrcID = TEXT_RSRC_ID + (100*theOffset) + (theItem - 1);
  169.         theRsrcHandle = GetResource('TEXT', theRsrcID);
  170.         anError = ResError();
  171.         if ((!anError) && (gSrcWind_TEH))
  172.         {
  173.             support_undo("Template", TRUE);
  174.             HLock(theRsrcHandle);
  175.             // Delete any selected text before the insertion
  176.             TEDelete(gSrcWind_TEH);
  177.             // stick in the text
  178.             TEInsert(&(**theRsrcHandle), GetHandleSize(theRsrcHandle), gSrcWind_TEH);
  179.             gSrcWind_dirty = true;
  180.             ReleaseResource(theRsrcHandle);
  181.             // scroll to new insertion point
  182.             ShowSelect();
  183.         }
  184.     }
  185. } // HandleTemplateMenu
  186.  
  187.  
  188. // ==============================================
  189. void KillTemplateMenu(void)
  190. {
  191. } // KillTemplateMenu
  192.